#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>


int* productExceptSelf(int* nums, int numsSize) {
	int count = 0;
	int j = 0;
	int* ans = (int*)malloc(sizeof(int) * numsSize);
	for (int i = 0; i < numsSize; i++)
	{
		
		int sum = 1;
		for (j = 0; j < numsSize; j++)
		{
			if (j != i)
			{
				sum = nums[j] * sum;
			}
		}
		ans[count++] = sum;
	}

	return ans;
}

int cmp(const void* p1, const void* p2)
{
	return (*(int*)p1 - *(int*)p2);
}

//error
//int* findDisappearedNumbers(int* nums, int numsSize) {
//	int* ans = (int*)malloc(sizeof(int) * numsSize);
//	int count = 0;
//	for (int i = 0; i < numsSize; i++)
//	{
//		ans[i] = i + 1;
//	}
//	qsort(nums, numsSize, sizeof(int), cmp);
//	for (int i = 0; i < numsSize; i++)
//	{
//		if (nums[i] != ans[i])
//		{
//			ans[count++] = ans[i];
//		}
//	}
//
//	int* rans = (int*)realloc(ans, sizeof(int) * count - 1);
//
//	return ans;
//}

int* findDisappearedNumbers(int* nums, int numsSize) {
	int* ans = (int*)malloc(sizeof(int) * numsSize);
	int count = 0;
	int flag = 0;
	for (int i = 0; i < numsSize; i++)
	{
		ans[i] = i + 1;
	}

	qsort(nums, numsSize, sizeof(int), cmp);

	for (int i = 0; i < numsSize; i++)
	{
		for (int j = 0; j < numsSize; j++)
		{
			flag = 0;
			if (nums[j] == ans[i])
			{
				flag = 1;
				break;
			}
		}

		if (flag == 0)
		{
			ans[count++] = ans[i];
		}
	}

	int* rans = (int*)realloc(ans, sizeof(int) * count - 1);

	return ans;
}

int main()
{
	int nums[] = { 4,3,2,7,8,2,3,1 };
	int len = sizeof(nums) / sizeof(int);
	//int* p = productExceptSelf(nums, len);
	//for (int i =0; i<len; i++)
	//{
	//	printf("%d ", p[i]);
	//}

	int* p = findDisappearedNumbers(nums,len);

	return 0;
}